package cn.edu.ujn.lab2.dao;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.query.Query;

import cn.edu.ujn.lab2.db.HibernateSessionFactory;
import cn.edu.ujn.lab2.model.Dlb;
import cn.edu.ujn.lab2.model.Zyb;

public class ZyDaoImp {
	public Zyb getOneZy(Integer zyId) {
		try{
			Session session=HibernateSessionFactory.getSession();
			Transaction ts=session.beginTransaction();
			Query query=session.createQuery("from Zyb where id=?");
			query.setParameter(0, zyId);
			query.setMaxResults(1);
			Zyb zy=(Zyb) query.uniqueResult();
			ts.commit();
			HibernateSessionFactory.closeSession();
			return zy;
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}
	public List getAll() {
		try{
			Session session=HibernateSessionFactory.getSession();
			Transaction ts=session.beginTransaction();
			List list=session.createQuery("from Zyb").list();
			ts.commit();
			HibernateSessionFactory.closeSession();
			return list;
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}

}
